<?
require_once 'config.php';
$list_office = list_office();
$bg_errorMsg = '';
$bg_success = '';
$action = getValue('action','str','POST','');
if($action == 'execute'){
    $name_field = getValue('name','str','POST','',2);
    $email_field = getValue('email','str','POST','',2);
    if(!filter_var($email_field, FILTER_VALIDATE_EMAIL)){
        $bg_errorMsg .= 'Email không đúng định dạng <br>';
    }
    $title_field = getValue('title','str','POST','',2);
    $content_field = getValue('content','str','POST','',2);
    $con_date = time();
    $myform = new generate_form();
    $myform->add('con_name','name_field',0,1,'',1,'Bạn chưa nhập tên');
    $myform->add('con_email','email_field',0,1,'',1,'Bạn chưa nhập email');
    $myform->add('con_subject','title_field',0,1,'',1,'Bạn chưa nhập tiêu đề');
    $myform->add('con_detail','content_field',0,1,'',1,'Bạn chưa nhập nội dung');
    $myform->add('con_date','con_date',1,1,0);
    $myform->addTable('contact');
    $bg_errorMsg .= $myform->checkdata();
    if($bg_errorMsg == ''){
        $db = new db_execute($myform->generate_insert_SQL());
        $bg_success = 1;
    }
    
}
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
<head>
<title>Liên hệ</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href="/home/css/style.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="wrap"> 	
   <? include 'includes/inc_header.php'?>		
	<div class="about-top">
		<div class="about-box">
			   <div class="section group">
				<div class="col span_2_of_3">
				  <div class="contact-form">
				  	<h2>Gửi liên hệ</h2>
					    <form class="form" action="<?=$_SERVER['REQUEST_URI']?>" method="POST" onsubmit="return validSend()">
                   <?=($bg_errorMsg ? '<div class="alert red">'.$bg_errorMsg.'</div>' : '')?>
                   <?=($bg_success ? '<div class="alert alert-success blue">'.'Cảm ơn bạn đã gửi liên hệ. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!'.'</div>' : '')?> 
					    	<div>
						    	<span><label>Họ tên</label></span>
						    	<span><input type="text" value="" placeholder="Họ tên của bạn" class="inputtxt textbox" name="name" id="name_contact"/></span>
						    </div>
						    <div>
						    	<span><label>Tiêu đề</label></span>
						    	<span><input type="text" value="" placeholder="Tiêu đề liên hệ" class="inputtxt textbox" name="title" id="title_contact"/></span>
						    </div>
						    <div>
						     	<span><label>Email</label></span>
						    	<span><input type="text" value="" placeholder="Email của bạn" class="inputtxt textbox" name="email" id="email_contact"/></span>
						    </div>
						    <div>
						    	<span><label>Nội dung</label></span>
						    	<span><textarea placeholder="Nội dung liên hệ" class="inputtxt inputtxtArea" name="content" id="content_contact"></textarea></span>
						    </div>
						   <div><input type="hidden" name="action" value="execute"/> 
						   		<span><input type="submit" value="Gửi"></span>
						  </div>
					    </form>
				  </div>
  				</div>
				<div class="col span_1_of_contact">
					  <div class="company_address">
				     	     <? $list_office = list_office();?>
                        <p><span><?=$list_office['off_name']?></span></p>
                        <p><span>Địa chỉ: </span><?=$list_office['off_address']?></p>
                        <p><span>Số điện thoại: </span><?=$list_office['off_phone']?></p>
                        <p><span>Hotline: </span><?=$list_office['off_hotline']?></p>
                        <p><span>Email: </span><?=$list_office['off_email']?></p>
                        <p><span>Website: </span><?=$list_office['off_website']?></p>
				   </div>
				 </div>
				 <div class="clear"></div> 	
			  </div>
			</div>
		 </div>
	 <div class="footer">
	    <? include 'includes/inc_footer.php'?>
	</div>
  </div>
</body>
</html>